Private Sub CommandButton1_Click() x0 = ActiveCell.Row y0 = ActiveCell.Column nometabella = Cells(x0, y0) x = x0 + 1 y = y0 elencocampi = "" While (Cells(x, y) <> "") If (y > y0) Then elencocampi = elencocampi & ", " elencocampi = elencocampi & Cells(x, y) y = y + 1 Wend nc = y Cells(x0, nc + 1) = "CREATE TABLE " & nometabella & "(" & elencocampi & ");" End Sub Private Sub CommandButton2_Click() Dim x As Integer Dim y As Integer x0 = ActiveCell.Row y0 = ActiveCell.Column nometabella = Cells(x0, y0) x = x0 + 1 y = y0 elencocampi = "" While (Cells(x, y) <> "") If (y > y0) Then elencocampi = elencocampi & ", " elencocampi = elencocampi & "'" & Cells(x, y) & "'" 'elencocampi = elencocampi & Cells(x, y) y = y + 1 Wend nc = y Cells(x, nc + 1) = "INSERT INTO " & nometabella & "(" & elencocampi & ") VALUES " Debug.Print x, y0 x = x + 1 While (Cells(x, y0) <> "") elencocampi = "(" y = y0 While (y < nc) If (y > y0) Then elencocampi = elencocampi & ", " pos = InStr(1, Cells(x, y), "/") If (pos > 0) Then valore = Format$(Cells(x, y), "yyyy-mm-dd") Debug.Print pos, valore elencocampi = elencocampi & "'" & valore & "'" Else elencocampi = elencocampi & "'" & Cells(x, y) & "'" End If y = y + 1 Wend elencocampi = elencocampi & ")" If (Cells(x + 1, y0) <> "") Then elencocampi = elencocampi & ", " Else elencocampi = elencocampi & ";" Cells(x, nc + 1) = elencocampi x = x + 1 Wend 'elencocampi = ";" 'Cells(x, nc + 1) = elencocampi End Sub Private Sub CommandButton3_Click() Dim valore As String 'miofile = ActiveWorkbook.Path & "\test_" & ActiveSheet.Name & ".sql" miofile = "C:\Users\loure\Documents\" & LCase(ActiveSheet.Name) & ".sql" Open miofile For Output As #1 x0 = ActiveCell.Row y0 = ActiveCell.Column nometabella = Cells(x0, y0) x = x0 + 1 y = y0 elencocampi = "" While (Cells(x, y) <> "") If (y > y0) Then elencocampi = elencocampi & ", " elencocampi = elencocampi & "'" & Cells(x, y) & "'" 'elencocampi = elencocampi & Cells(x, y) y = y + 1 Wend nc = y Print #1, "INSERT INTO " & nometabella & "(" & elencocampi & ") VALUES " Debug.Print x, y0 x = x + 1 While (Cells(x, y0) <> "") elencocampi = "(" y = y0 While (y < nc) If (y > y0) Then elencocampi = elencocampi & ", " pos = InStr(1, Cells(x, y), "/") If (pos > 0) Then valore = Format$(Cells(x, y), "yyyy-mm-dd") Debug.Print pos, valore elencocampi = elencocampi & "'" & valore & "'" Else elencocampi = elencocampi & "'" & Cells(x, y) & "'" End If y = y + 1 Wend elencocampi = elencocampi & ")" If (Cells(x + 1, y0) <> "") Then elencocampi = elencocampi & ", " Else elencocampi = elencocampi & ";" Print #1, elencocampi x = x + 1 Wend 'elencocampi = ";" 'Cells(x, nc + 1) = elencocampi Close #1 MsgBox "salvato " & miofile End Sub